package com.crm.service.impl.customerManager;

import com.crm.dao.mapper.customMapper.customerManagerCustomMapper.CustomerReturnCustomMapper;
import com.crm.dao.mapper.customerManager.CustomerReturnMapper;
import com.crm.model.entity.customerManager.CustomerReturn;
import com.crm.model.entity.customerManager.CustomerReturnExample;
import com.crm.model.qo.customerManager.CustomerReturnQO;
import com.crm.model.vo.customerManager.CustomerReturnVO;
import com.crm.service.customerManager.CustomerReturnDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Author ：pym
 * @ Date   ：2021/1/22 16:26
 */
@Service
public class CustomerReturnDbServiceImpl implements CustomerReturnDbService {
    @Autowired //自动生成的
    CustomerReturnMapper customerReturnMapper;
    @Autowired
    CustomerReturnCustomMapper customerReturnCustomMapper;

    @Override
    public int insertCustomerReturn(CustomerReturn customerReturn) {
        return customerReturnMapper.insert(customerReturn);
    }

    /**
     * 通过客户号查询退回记录
     * @param customerId 客户id
     * @return
     */
    @Override
    public CustomerReturn selectCustomerReturnNew(String customerId) {
        CustomerReturnExample customerReturnExample = new CustomerReturnExample();
        CustomerReturnExample.Criteria criteria = customerReturnExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        customerReturnExample.setOrderByClause(" return_tm desc ");
        List<CustomerReturn> customerReturns = customerReturnMapper.selectByExample(customerReturnExample);
        if(customerReturns != null && !customerReturns.isEmpty()){
            return customerReturns.get(0);
        }
        return null;
    }

    /**
     * 系统收回客户记录
     * @param moveCustomerQO
     * @param order
     * @return
     */
    @Override
    public List<CustomerReturnVO> getFollowPlanListByDate(CustomerReturnQO moveCustomerQO, StringBuilder order) {
        return customerReturnCustomMapper.getFollowPlanListByDate(moveCustomerQO,order);
    }

    /**
     * 修改回退状态
     * @param customerReturnId
     */
    @Override
    public void backCustomerReturn(String customerReturnId) {
        customerReturnCustomMapper.backCustomerReturn(customerReturnId);
    }
}
